import Vue from 'vue'
import Router from 'vue-router'
import routes from './routes'
import Navigation from '../plugins/vue-navigation/src'
import store from '../store'
import { init_page } from '@/utils/cache_pages'
import interceptor from './interceptor'
import './stupidbackend'
import quit from './quit'
Vue.use(Router)
const router = new Router({
  routes
})
router.beforeEach(async (to, from, next) => {
  //console.log(to)
  onpopstate.from = history.state
  Object.assign(to.params, init_page(to)) // 解决路刷新 params 为空问题
  await interceptor(to, from, next) // 添加路由拦截器
})


Vue.use(Navigation, {router})
const $navigation = Vue.prototype.$navigation
$navigation.on('forward', function (to, form) {
  navigationDirection = 'forward'
  //console.log('forward')
})
$navigation.on('back', function (to, form) {
  navigationDirection = 'back'
  //console.log('back')
})
quit(router, $navigation)
window.$navigation = $navigation
window.router = router
export default router
